//中文
var a = ['你知道吗', '六月', '一日', '星期一', '是', '儿童节'];
//英语
var b = ['do you know', 'June', 'One day', 'Monday', 'Yes', 'Children\'s day'];

// 左边语言显示
var btn_if = document.querySelectorAll("#btn_if button");
// 右边语言显示
var btn_that = document.querySelectorAll("#btn_that button");
// 点击切换语言
var btn_swap = document.querySelector("#btn_swap");
// 左边的输入内容
var text_if = document.querySelector("#text_if");
// 右边的翻译结果
var text_that = document.querySelector("#text_that");
// 翻译按钮
var btn_res = document.querySelector("#btn_res");
// 默认语言是中文
var lang = 'a';
// 切换语言
function lan() {
	// 切换默认语言用的
	if (lang == 'a') {
		lang = 'b';
	} else {
		lang = 'a';
	}
	for (var i = 0; i < btn_if.length; i++) {
		btn_if[i].classList.remove('btn-primary');
		btn_if[i].classList.remove('btn-light');
		btn_that[i].classList.remove('btn-primary');
		btn_that[i].classList.remove('btn-light');
	}
	switch (lang) {
		case 'a':
			btn_if[0].classList.add('btn-primary');
			btn_if[1].classList.add('btn-light');
			btn_that[0].classList.add('btn-primary');
			btn_that[1].classList.add('btn-light');
			break;
		case 'b':
			btn_if[0].classList.add('btn-light');
			btn_if[1].classList.add('btn-primary');
			btn_that[0].classList.add('btn-light');
			btn_that[1].classList.add('btn-primary');
			break;
	}

}
// 点击翻译按钮的方法
function res() {
	var data;
	var if_text = false;

	for (var i in a) {
		if (text_if.value == a[i]) {
			if_text = true;
			data = a;
			text_that.value = b[i];

			if (lang == 'b') {
				lan();
			}
		}
	}
	for (var i in b) {
		if (text_if.value == b[i]) {
			if_text = true;
			data = b;
			text_that.value = a[i];

			if (lang == 'a') {
				lan();
			}
		}
	}
	if (!if_text) {
		text_that.value = '';
		alert("无法翻译");
	}
}
